package com.xbfinance.portal.service.impl;


import com.xbfinance.portal.pojo.po.P2pAccountCash;
import com.xbfinance.portal.dao.P2pAccountCashMapper;
import com.xbfinance.portal.service.PortalGetMoneyCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.DecimalFormat;
import java.util.Date;

@Service
@Transactional
public class PortalGetMoneyCheckServiceImpl implements PortalGetMoneyCheckService {
    @Autowired
    private P2pAccountCashMapper p2pAccountCashMapper;
    @Override
    public int saveGetMoneyCheck(P2pAccountCash p) {
        //Service赋值cashstatus=0   fee  addtime
        int i = 0;
        try {
            p.setCashstatus((byte)0);
            double fee = p.getMoney()*0.05;
            DecimalFormat df = new DecimalFormat("#.00");
            String feeStr = df.format(fee);
            double d = Double.parseDouble(feeStr);
            p.setFee(d);
            p.setAddtime(new Date());
            i = p2pAccountCashMapper.insertSelective(p);
        }catch (Exception e){
            e.printStackTrace();
        }
        return i;
    }
}
